package cn.lingyangwl.agile.food.core.manager;

import cn.hutool.core.collection.CollUtil;
import cn.lingyangwl.agile.food.core.mapper.StoreGoodsMapper;
import cn.lingyangwl.agile.food.model.entity.StoreGoods;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 门店商品 仓储层
 *
 * @author shenguangyang
 */
@Slf4j
@Repository
public class StoreGoodsManager extends ServiceImpl<StoreGoodsMapper, StoreGoods>
    implements IService<StoreGoods> {

    public List<StoreGoods> listByGoodsId(Long goodsId, Boolean isPublish) {
        return this.list(StoreGoods.lqw().eq(StoreGoods::getGoodsId, goodsId).eq(StoreGoods::getIsPublish, isPublish));
    }

    public List<StoreGoods> listByGoodsIds(List<Long> goodsIds, Boolean isPublish) {
        if (CollUtil.isEmpty(goodsIds)) {
            return Collections.emptyList();
        }
        return this.list(StoreGoods.lqw().in(StoreGoods::getGoodsId, goodsIds)
                .eq(Objects.nonNull(isPublish), StoreGoods::getIsPublish, isPublish));
    }

    public void deleteByGoodIds(List<Long> goodsIds) {
        if (CollUtil.isEmpty(goodsIds)) {
            return;
        }
       this.remove(StoreGoods.lqw().in(StoreGoods::getGoodsId, goodsIds));
    }
}
